home *** CD-ROM | disk | FTP | other *** search
/ boe.pres.k12.wv.us / boe.pres.k12.wv.us.zip / boe.pres.k12.wv.us / Utilities / Xerox Workcentre 5335 / Windows Scan / 32-bit_x86 / Russian / cpsimage.cab / data / docio / docFormatService.elf < prev    next >
Text File  |  2009-03-16  |  6KB  |  211 lines

  1. // $Id: docFormatService.elf,v 1.6 2008/07/10 20:25:53 campanel Exp $
  2.  
  3. LoadClasses(filename:"xeng");
  4. #load "sys/stdio.elf";
  5. #load "docio/doctransforms.elf";
  6.  
  7. PROCEDURE makeAddFromDelete (LIST deleteList, INTEGER addLength) RETURNS (LIST addList)
  8. {
  9.     INTEGER ii;
  10.     INTEGER index;
  11.  
  12.     if (doTrace)
  13.         print "Running makeAddFromDelete";
  14.     // put all pages on the list
  15.     for (ii=1; ii<=addLength; ii++) {
  16.         /* make a copy of ii at current value; list holds a reference to object */
  17.         addList.insert(obj: ii.Copy());
  18.     }
  19.     addList.sort( numeric: TRUE, descending: FALSE);
  20.  
  21.     // make sure the objects are removed from the list "far end" first
  22.     deleteList.sort( numeric: TRUE, descending: FALSE);
  23.     // now remove any page marked as delete
  24.     /*
  25.     foreach ( deleteList: pn ) {
  26.         print "Removing "+pn;
  27.         addList.remove( entry: pn - 1);
  28.     }
  29.     */
  30.     
  31.     INTEGER i;
  32.     foreach ( deleteList: pn ) {
  33.         print "Removing "+pn;
  34.         index = pn.Copy();
  35.         for(i = 0; i < addList.length(); i++)
  36.         {
  37.             if (addList.ref(entry: i) == index)
  38.             {
  39.                 addList.remove(entry: i);
  40.             }
  41.         }
  42.     }
  43. }
  44.  
  45. PROCEDURE docAddAllPages (DOCUMENTREADER dr, DOCUMENTWRITER dw, BOOLEAN doTrace)
  46.                        RETURNS (BOOLEAN success, INTEGER pgcnt)
  47. {
  48.     INTEGER srcPgs = dr.getPageCount();
  49.     INTEGER ii = 0;
  50.     INTEGER offset;
  51.     XIPIMAGE curPg;
  52.     XIPIMAGE destimg;
  53.     BOOLEAN usingSameImg;
  54.  
  55.     if (doTrace)
  56.         print "Running docAddAllPages";
  57.  
  58.     pgcnt = 0;
  59.     for (ii = 0; ii<srcPgs; ii++) {
  60.         offset = ii+1;
  61.         if (doTrace) print "    process page "+offset;
  62.         curPg = dr.getPage( pgnum: offset );
  63.         if (!curPg) {
  64.             if (doTrace)
  65.                 print "    Could not acquire page image";
  66.             success = FALSE;
  67.             return;
  68.         }
  69.         TransformPage (inpage: curPg, todoc: dw, doTrace: doTrace)
  70.             RETURNS (outpage: destimg, isOriginal: usingSameImg);
  71.         if (!destimg) {
  72.             if (doTrace)
  73.                 print "    Transfomation of page failed";
  74.             success = FALSE;
  75.             return;
  76.         }
  77.         if (doTrace)
  78.             print "    appending page image from TransformPage to DOCUMENTWRITER";
  79.         pgcnt = dw.appendPage(pgImg: destimg);
  80.     }
  81.  
  82.     success = TRUE;
  83. }
  84.  
  85.  
  86. PROCEDURE docAddSelectPages (DOCUMENTREADER dr, DOCUMENTWRITER dw, LIST pageList, BOOLEAN doTrace)
  87.                        RETURNS (BOOLEAN success, INTEGER pgcnt)
  88. {
  89.     INTEGER srcPgs = dr.getPageCount();
  90.     INTEGER ii = 0;
  91.     XIPIMAGE curPg;
  92.     XIPIMAGE destimg;
  93.     BOOLEAN usingSameImg;
  94.  
  95.     if (doTrace)
  96.         print "Running docAddSelectPages";
  97.  
  98.     foreach ( pageList : index) {
  99.         if (doTrace) print "    process page "+index;
  100.         if (index > srcPgs) {
  101.             if (doTrace)
  102.                 print "    Page index exceeds page count";
  103.             success = FALSE;
  104.             return;
  105.         }
  106.         curPg = dr.getPage( pgnum: index );
  107.         if (!curPg) {
  108.             if (doTrace)
  109.                 print "    Could not acquire page image";
  110.             success = FALSE;
  111.             return;
  112.         }
  113.         TransformPage (inpage: curPg, todoc: dw, doTrace: doTrace)
  114.             RETURNS (outpage: destimg, isOriginal: usingSameImg);
  115.         if (!destimg) {
  116.             if (doTrace)
  117.                 print "    Transfomation of page failed";
  118.             success = FALSE;
  119.             return;
  120.         }
  121.         if (doTrace)
  122.             print "    appending page image from TransformPage to DOCUMENTWRITER";
  123.         pgcnt = dw.appendPage(pgImg: destimg);
  124.     }
  125.  
  126.     success = TRUE;
  127. }
  128.  
  129.  
  130.  
  131. /**********************************************************************************/
  132. /*****************************   SCRIPT ENTRY *************************************/
  133. /**********************************************************************************/
  134. BOOLEAN doTrace = FALSE;
  135. BOOLEAN success = FALSE;
  136. INTEGER destPgCnt = 0;
  137.  
  138. /* Here are the import variables */
  139. IMPORT INTEGER debugLevel = 0;
  140.     
  141. IMPORT STRING srcFile;
  142. IMPORT STRING destFile;
  143. IMPORT STRING destFormat;
  144. IMPORT STRING destSubtype = "none";
  145.  
  146. IMPORT LIST pagesToRemove;
  147.  
  148. if (debugLevel & 2) {
  149.     doTrace = TRUE;
  150.     print "***** Running docFormatService *****";
  151. }
  152.  
  153. /* Test input vars */
  154. if (!srcFile) {
  155.     SetStatus(op: "stop", msg: "No source image was provided");
  156.     return;
  157. }
  158. if (!destFile) {
  159.     SetStatus(op: "stop", msg: "No destination image was provided");
  160.     return;
  161. }
  162.  
  163. if (debugLevel & 4)
  164.     help "var";
  165.  
  166. DOCUMENTREADER drrd = CreateDocumentReader( filename: srcFile );
  167. if (!drrd) {
  168.     SetStatus(op: "stop", msg: "Failed to create DOCUMENTREADER from "+srcFile );
  169.     return;
  170. }
  171.  
  172. if (!destFormat) {
  173.     DOCUMENTWRITER dwwt = CreateDocumentWriter( filename: destFile );
  174. } else {
  175.     DOCUMENTWRITER dwwt = CreateDocumentWriter( filename: destFile, format: destFormat, subtype: destSubtype );
  176. }
  177.  
  178. if (!pagesToRemove) {
  179.     docAddAllPages (dr: drrd, dw: dwwt, doTrace: doTrace)
  180.                        RETURNS (success: success, pgcnt: destPgCnt);
  181. } else {
  182.     LIST addPages;
  183.     INTEGER pgcnt = drrd.getPageCount();
  184.  
  185.     if (doTrace)
  186.         print "    Assemble list of pages to delete";
  187.  
  188.     makeAddFromDelete (deleteList: pagesToRemove, addLength: pgcnt)
  189.                        RETURNS (addList: addPages);
  190.  
  191.     if (debugLevel & 4) {
  192.         help "var";
  193.         print addPages;
  194.     }
  195.  
  196.     docAddSelectPages (dr: drrd, dw: dwwt, pageList: addPages, doTrace: doTrace)
  197.                        RETURNS (success: success, pgcnt: destPgCnt);
  198. }
  199.  
  200.  
  201. if (debugLevel & 4)
  202.     help "var";
  203.  
  204. if (!success) {
  205.     SetStatus(op: "stop", msg: "Document conversion NOT successful. Converted pages = "+destPgCnt);
  206.     return;
  207. }
  208.  
  209. if (doTrace)
  210.     print "    Document conversion successful. Converted pages = "+destPgCnt;
  211.